package com.tarena.sentinel.demo02;

import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class SDemo01Main {
    public static void main(String[] args) {
        SpringApplication.run(SDemo01Main.class,args);
        //定义一个绑定resource01资源的流控规则
        List<FlowRule> flowRules=new ArrayList<>();
        //在集合中添加唯一的一个流控规则
        FlowRule flowRule=new FlowRule();
        //定义这个规则的条件.最少给三个必要属性
        //1. 这个规则绑定限制哪个资源
        flowRule.setResource("resource01");
        //2. 流控的维度 0=并发限流 1=qps限流
        flowRule.setGrade(1);
        //3. 限流阈值(上限)
        flowRule.setCount(1);
        flowRules.add(flowRule);
        //最终用sentinel加载规则.
        FlowRuleManager.loadRules(flowRules);
    }
}
